package com.zs.blog.controller;


import com.zs.blog.model.ResponseResult;
import com.zs.blog.model.dto.TagEditDTO;
import com.zs.blog.model.dto.TagSearchDTO;
import com.zs.blog.model.vo.*;
import com.zs.blog.service.ITagService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Title: TagController
 * @Author zs
 * @Package com.zs.blog.controller
 * @Date 2024/10/13 21:28
 * @description: 标签接口层
 */
@RestController
@Tag(name = "标签相关接口")
public class TagController {

    public ITagService tagService;

    @Autowired
    private TagController(ITagService tagService) {
        this.tagService = tagService;
    }

    @GetMapping("/admin/tag/list")
    @Operation(summary = "获取标签分页列表")
    public ResponseResult<PageInfoVO<TagListVO>> listTagWithPagination(Integer pageNum,Integer pageSize){
        PageInfoVO<TagListVO> listAllTag = tagService.listTagWithPagination(pageNum,pageSize);
        return ResponseResult.success(listAllTag);
    }

    @PostMapping("/admin/tag/search")
    @Operation(summary = "根据搜索条件获取标签分页列表")
    public ResponseResult<PageInfoVO<TagListVO>> listCategoryBySearchCondition(@RequestBody TagSearchDTO tagSearchDTO) {
        PageInfoVO<TagListVO> listCategoryBySearchCondition = tagService.listTagBySearchCondition(tagSearchDTO);
        return ResponseResult.success(listCategoryBySearchCondition);
    }

    @DeleteMapping("/admin/tag/delete")
    @Operation(summary = "根据标签ID删除标签")
    public ResponseResult<?> deleteCategory(@RequestBody List<Integer> tagIdList) {
        return tagService.deleteTagByIds(tagIdList);
    }

    @PutMapping("/admin/tag/add")
    @Operation(summary = "新增标签")
    public ResponseResult<?> addCategory(@RequestBody TagEditDTO tagEditDTO) {
        tagService.addOrUpdateTag(tagEditDTO);
        return ResponseResult.success();
    }

    @PostMapping("/admin/tag/update")
    @Operation(summary = "修改标签")
    public ResponseResult<?> updateCategory(@RequestBody TagEditDTO tagEditDTO){
        tagService.addOrUpdateTag(tagEditDTO);
        return ResponseResult.success();
    }

    @GetMapping("/admin/tag/{tagId}")
    @Operation(summary = "根据标签ID获取标签数据")
    public ResponseResult<TagEditVO> getCategoryByCategoryId(@PathVariable Long tagId){
        TagEditVO category = tagService.getTagByTagId(tagId);
        return ResponseResult.success(category);
    }

    @GetMapping("/portal/tag/list")
    @Operation(summary = "前台-获取标签列表")
    public ResponseResult<List<TagListVO>> listCategory(){
        List<TagListVO> listAllCategory = tagService.listTag();
        return ResponseResult.success(listAllCategory);
    }
}
